package com.kexilo.logging.domain;

import java.time.LocalDateTime;

/**
 * 日志记录抽象模型
 * 不依赖任何具体的audit实体，完全解耦
 * 
 * @author Kexilo
 */
public class LogRecord {
    
    public enum LogType {
        OPERATION,    // 操作日志
        LOGIN,        // 登录日志
        SECURITY,     // 安全日志
        AUDIT,        // 审计日志
        BUSINESS      // 业务日志
    }
    
    public enum LogLevel {
        INFO,
        WARN,
        ERROR,
        DEBUG
    }
    
    // 基础字段
    private LogType type;
    private LogLevel level;
    private String title;
    private String username;
    private String ip;
    private String userAgent;
    private String url;
    private String method;
    private String className;
    private String methodName;
    private String params;
    private String result;
    private Integer status;
    private String errorMsg;
    private Long costTime;
    private String traceId;
    private LocalDateTime operTime;
    
    // 扩展字段
    private String tenantId;
    private String deptName;
    private String operLocation;
    private String browser;
    private String os;
    
    // Builder模式构造器
    public static Builder builder() {
        return new Builder();
    }
    
    public static class Builder {
        private LogRecord logRecord = new LogRecord();
        
        public Builder type(LogType type) {
            logRecord.type = type;
            return this;
        }
        
        public Builder level(LogLevel level) {
            logRecord.level = level;
            return this;
        }
        
        public Builder title(String title) {
            logRecord.title = title;
            return this;
        }
        
        public Builder username(String username) {
            logRecord.username = username;
            return this;
        }
        
        public Builder ip(String ip) {
            logRecord.ip = ip;
            return this;
        }
        
        public Builder userAgent(String userAgent) {
            logRecord.userAgent = userAgent;
            return this;
        }
        
        public Builder url(String url) {
            logRecord.url = url;
            return this;
        }
        
        public Builder method(String method) {
            logRecord.method = method;
            return this;
        }
        
        public Builder className(String className) {
            logRecord.className = className;
            return this;
        }
        
        public Builder methodName(String methodName) {
            logRecord.methodName = methodName;
            return this;
        }
        
        public Builder params(String params) {
            logRecord.params = params;
            return this;
        }
        
        public Builder result(String result) {
            logRecord.result = result;
            return this;
        }
        
        public Builder status(Integer status) {
            logRecord.status = status;
            return this;
        }
        
        public Builder errorMsg(String errorMsg) {
            logRecord.errorMsg = errorMsg;
            return this;
        }
        
        public Builder costTime(Long costTime) {
            logRecord.costTime = costTime;
            return this;
        }
        
        public Builder traceId(String traceId) {
            logRecord.traceId = traceId;
            return this;
        }
        
        public Builder operTime(LocalDateTime operTime) {
            logRecord.operTime = operTime;
            return this;
        }
        
        public Builder tenantId(String tenantId) {
            logRecord.tenantId = tenantId;
            return this;
        }
        
        public Builder deptName(String deptName) {
            logRecord.deptName = deptName;
            return this;
        }
        
        public Builder operLocation(String operLocation) {
            logRecord.operLocation = operLocation;
            return this;
        }
        
        public Builder browser(String browser) {
            logRecord.browser = browser;
            return this;
        }
        
        public Builder os(String os) {
            logRecord.os = os;
            return this;
        }
        
        public LogRecord build() {
            if (logRecord.operTime == null) {
                logRecord.operTime = LocalDateTime.now();
            }
            return logRecord;
        }
    }
    
    // Getters and Setters
    public LogType getType() { return type; }
    public void setType(LogType type) { this.type = type; }
    
    public LogLevel getLevel() { return level; }
    public void setLevel(LogLevel level) { this.level = level; }
    
    public String getTitle() { return title; }
    public void setTitle(String title) { this.title = title; }
    
    public String getUsername() { return username; }
    public void setUsername(String username) { this.username = username; }
    
    public String getIp() { return ip; }
    public void setIp(String ip) { this.ip = ip; }
    
    public String getUserAgent() { return userAgent; }
    public void setUserAgent(String userAgent) { this.userAgent = userAgent; }
    
    public String getUrl() { return url; }
    public void setUrl(String url) { this.url = url; }
    
    public String getMethod() { return method; }
    public void setMethod(String method) { this.method = method; }
    
    public String getClassName() { return className; }
    public void setClassName(String className) { this.className = className; }
    
    public String getMethodName() { return methodName; }
    public void setMethodName(String methodName) { this.methodName = methodName; }
    
    public String getParams() { return params; }
    public void setParams(String params) { this.params = params; }
    
    public String getResult() { return result; }
    public void setResult(String result) { this.result = result; }
    
    public Integer getStatus() { return status; }
    public void setStatus(Integer status) { this.status = status; }
    
    public String getErrorMsg() { return errorMsg; }
    public void setErrorMsg(String errorMsg) { this.errorMsg = errorMsg; }
    
    public Long getCostTime() { return costTime; }
    public void setCostTime(Long costTime) { this.costTime = costTime; }
    
    public String getTraceId() { return traceId; }
    public void setTraceId(String traceId) { this.traceId = traceId; }
    
    public LocalDateTime getOperTime() { return operTime; }
    public void setOperTime(LocalDateTime operTime) { this.operTime = operTime; }
    
    public String getTenantId() { return tenantId; }
    public void setTenantId(String tenantId) { this.tenantId = tenantId; }
    
    public String getDeptName() { return deptName; }
    public void setDeptName(String deptName) { this.deptName = deptName; }
    
    public String getOperLocation() { return operLocation; }
    public void setOperLocation(String operLocation) { this.operLocation = operLocation; }
    
    public String getBrowser() { return browser; }
    public void setBrowser(String browser) { this.browser = browser; }
    
    public String getOs() { return os; }
    public void setOs(String os) { this.os = os; }
    
    @Override
    public String toString() {
        return "LogRecord{" +
                "type=" + type +
                ", level=" + level +
                ", title='" + title + '\'' +
                ", username='" + username + '\'' +
                ", ip='" + ip + '\'' +
                ", url='" + url + '\'' +
                ", method='" + method + '\'' +
                ", status=" + status +
                ", costTime=" + costTime +
                ", operTime=" + operTime +
                '}';
    }
}
